package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistnj;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistnj.vo.DpEastListNjPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistnj.vo.DpEastListNjRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistnj.vo.DpEastListNjSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpEastListNjDO;
import cn.iocoder.yudao.module.erp.service.dpeast.DpEastListNjService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

@Tag(name = "管理后台 - 南疆口岸仓东线清单")
@RestController
@RequestMapping("/erp/dp-east-list-nj")
@Validated
public class DpEastListNjController {

    @Resource
    private DpEastListNjService dpEastListNjService;

    @PostMapping("/create")
    @Operation(summary = "创建南疆口岸仓东线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-nj:create')")
    public CommonResult<Long> createDpEastListNj(@Valid @RequestBody DpEastListNjSaveReqVO createReqVO) {
        return success(dpEastListNjService.createDpEastListNj(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新南疆口岸仓东线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-nj:update')")
    public CommonResult<Boolean> updateDpEastListNj(@Valid @RequestBody DpEastListNjSaveReqVO updateReqVO) {
        dpEastListNjService.updateDpEastListNj(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除南疆口岸仓东线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-nj:delete')")
    public CommonResult<Boolean> deleteDpEastListNj(@RequestParam("id") Long id) {
        dpEastListNjService.deleteDpEastListNj(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得南疆口岸仓东线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-nj:query')")
    public CommonResult<DpEastListNjRespVO> getDpEastListNj(@RequestParam("id") Long id) {
        DpEastListNjDO dpEastListNj = dpEastListNjService.getDpEastListNj(id);
        return success(BeanUtils.toBean(dpEastListNj, DpEastListNjRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得南疆口岸仓东线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-nj:query')")
    public CommonResult<PageResult<DpEastListNjRespVO>> getDpEastListNjPage(@Valid DpEastListNjPageReqVO pageReqVO) {
        PageResult<DpEastListNjDO> pageResult = dpEastListNjService.getDpEastListNjPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpEastListNjRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出南疆口岸仓东线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-nj:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpEastListNjExcel(@Valid DpEastListNjPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpEastListNjDO> list = dpEastListNjService.getDpEastListNjPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "南疆口岸仓东线清单.xls", "数据", DpEastListNjRespVO.class,
                        BeanUtils.toBean(list, DpEastListNjRespVO.class));
    }

}